<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
if (!ispost())
{
    exit();
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
$g_betname_3or5 = judge_type($gametype);
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
require_once( "class_3d/RateConfig_3d.php" );
require_once( "class_3d/SRate_3d.php" );
$ui = new UI_3D(true);
$conf = new Config();
$RateConfig_3d = new RateConfig_3d($gametype);
$SRate_3d = new SRate_3d($gametype);
$today = date("Y-m-d");
$bettypegroup = getvar("palygroup");
$betmin = $conf->get("betmin_{$tbl}");
$setMomney = getvar("setMomney");
$showSubid = getvar("subid");
$showSubid = isset($RateConfig_3d->subArr[$showSubid]) ? $showSubid : "0";
unset($_POST['setMomney']);
unset($_POST['timebtnType']);
unset($_POST['subid']);
if ($curruser['enabled'] == 0 || $curruser['enabled'] == 2)
{
    $ui->showErrorPage("帐号已被暂停使用");
    exit();
}
else if (1 < $curruser['acl'])
{
    $ui->showErrorPage("非会员无法下注");
    exit();
}
$disk = intval(getvar("disk"));
if (!isset($curruser["disk{$disk}"]) || $curruser["disk{$disk}"] != 1)
{
    $ui->showErrorPage("盘类错误");
    exit();
}
unset($_POST['disk']);
$diskStr = $RateConfig_3d->diskArr[$disk];
$diskStr2 = $g_disk_name[$disk];
$tempArr = array("g3" => "g3", "g6" => "g6");
if (!isset($tempArr[$bettypegroup]))
{
    $ui->showErrorPage("不正确的玩法页面");
    exit();
}
else if ($setMomney < $betmin)
{
    $ui->showErrorPage("下注金额不能小於最低限额(" . $betmin . "元)");
    exit();
}
unset($tempArr);
include_once( "BetChk.php" );
$BetChk = new BetChk($today, $gametype);
if ($lotto_3d = $BetChk->chkBetDate($today))
{
    $lotto_id = $lotto_3d['id'];
    $round = $lotto_3d['round'];
    if ($bettypegroup == "g3")
    {
        $cutNum = 19;
    }
    else
    {
        $cutNum = 26;
    }
    $showBetTable = array();
    $rateArr = array();
    $amountsDataArr = array();
    if (!isset($RateConfig_3d->subArr[$showSubid]))
    {
        $betOKFlag = false;
        $timeTemp = date("YmdHis") . "-1";
        $errMsg = "({$tbl})No.{$timeTemp} 会员下注(G):不正确的subid:idG-{$bettypegroup}, subid-{$showSubid}";
        write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
        $ui->showErrorPage("请勿用非法方式下注，你的的IP已被记录，若有任何问题请洽管理员。(errorNo.{$timeTemp})");
        exit();
    }
    foreach ($_POST as $key => $val)
    {
        $betOKFlag = true;
        $tempArr = array();
        $bettype = substr($key, 1);
        $arrayFlag = is_array($_POST[$key]);
        $checkNumMust = $bettype - $cutNum;
        $betSubIdx = $bettype . "_" . $showSubid;
        if ($arrayFlag)
        {
            if (!in_array($bettype, $RateConfig_3d->playGroupArr[$bettypegroup]))
            {
                $betOKFlag = false;
                $timeTemp = date("YmdHis") . "-2";
                $errMsg = "({$tbl})No.{$timeTemp} 会员下注G:不正确的玩法:id-" . $bettype;
                write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                $ui->showErrorPage("请勿用非法方式下注，你的的IP已被记录，若有任何问题请洽管理员。<br />错误讯息：No.{$timeTemp}");
                exit();
            }
            foreach ($val as $val2)
            {
                if (!$RateConfig_3d->checkBetNumber($bettype, $val2))
                {
                    $betOKFlag = false;
                    $timeTemp = date("YmdHis") . "-3";
                    $errMsg = "({$tbl})No.{$timeTemp} 会员下注G:不正确的内容:id-" . $bettype . ",num-" . $val2 . ", subid-{$showSubid}";
                    write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                    $ui->showErrorPage("请勿用非法方式下注，你的的IP已被记录，若有任何问题请洽管理员。<br />错误讯息：No.{$timeTemp}");
                    exit();
                }
            }
            sort($val);
            $valStr = implode(",", $val);
            $valNum = implode("", $val);
            $coutVal = count($val);
            if ($coutVal < $checkNumMust)
            {
                $betOKFlag = false;
                $showBetTable[] = array("bettype" => $g_betname_3or5[$betSubIdx], "nums" => $valStr, "rate" => "--", "betmoney" => "<font class=\"red\">勾选号码不足，无法下注</font>", "betflag" => false);
                continue;
            }
            if ($checkNumMust < $coutVal)
            {
                $betOKFlag = false;
                $showBetTable[] = array("bettype" => $g_betname_3or5[$betSubIdx], "nums" => $valStr, "rate" => "--", "betmoney" => "<font class=\"red\">勾选号码过多，无法下注</font>", "betflag" => false);
                continue;
            }
        }
        else
        {
            if ($bettype != 29)
            {
                $betOKFlag = false;
                $timeTemp = date("YmdHis") . "-3";
                $errMsg = "({$tbl})No.{$timeTemp} 会员下注G:不正确的页面玩法:id-{$bettype}, subid-{$showSubid}";
                write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                $ui->showErrorPage("请勿用非法方式下注1，你的的IP已被记录，若有任何问题请洽管理员。<br />错误讯息：No.{$timeTemp}");
                exit();
            }
            if (!$RateConfig_3d->checkBetNumber($bettype, $val))
            {
                $betOKFlag = false;
                $timeTemp = date("YmdHis") . "-4";
                $errMsg = "({$tbl})No.{$timeTemp} 会员下注G全包:不正确的内容:id-" . $bettype . ",num-" . $val . ",subid-{$showSubid}";
                write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                $ui->showErrorPage("请勿用非法方式下注，你的的IP已被记录，若有任何问题请洽管理员。<br />错误讯息：No.{$timeTemp}");
                exit();
                break;
            }
            $valStr = "全包";
            $valNum = "1";
        }
        if (!isset($rateArr[$betSubIdx]))
        {
            $tempRateBaseArr = $SRate_3d->getRates($lotto_id, $disk, $bettype, $showSubid);
            if ($tempRateBaseArr == false)
            {
                $betOKFlag = false;
                $timeTemp = date("YmdHis") . "-5";
                $showBetTable[] = array("bettype" => $g_betname_3or5[$betSubIdx], "nums" => $valStr, "rate" => "--", "betmoney" => "<font class=\"red\">无赔率资料无法下注</font>", "betflag" => false);
                $errMsg = "({$tbl})No.{$timeTemp}会员下注G:无该玩法之赔率值:id-{$bettype}, subid-{$showSubid}";
                write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
                continue;
            }
            $user_id = $SRate_3d->getAcl5ID($curruser['id'], $curruser['acl']);
            if ($tempRateBaseArr2 = $SRate_3d->getRatesS($lotto_id, $bettype, $user_id, $showSubid))
            {
                $tempRateArr = array();
                foreach ($tempRateBaseArr as $key2 => $val2)
                {
                    $tempRateArr[$key2] = $tempRateBaseArr[$key2] - $tempRateBaseArr2[$key2];
                }
                $rateArr[$betSubIdx] = $tempRateArr;
            }
            else
            {
                $rateArr[$betSubIdx] = $tempRateBaseArr;
            }
        }
        if ($arrayFlag)
        {
            $rate = 1000000;
            foreach ($val as $val2)
            {
                $rateTemp = $RateConfig_3d->getRateFromRateArr($bettype, $val2, $rateArr[$betSubIdx]);
                $rate = min($rate, $rateTemp);
            }
        }
        else
        {
            $rate = $RateConfig_3d->getRateFromRateArr($bettype, $val, $rateArr[$betSubIdx]);
        }
        if ($rate <= 1)
        {
            $betOKFlag = false;
            $showBetTable[] = array("bettype" => $g_betname_3or5[$betSubIdx], "nums" => $valStr, "rate" => "--", "betmoney" => "<font class=\"red\">勾选号码中有错误的赔率值，无法下注</font>", "betflag" => false);
            $errMsg = "({$tbl})会员下注G:赔率值错误:id-" . $bettype . ",num-" . $valStr . ",subid-" . $showSubid;
            write_exceptional_log($curruser['id'], $curruser['acl'], $lotto_id, $errMsg);
            continue;
        }
        if ($betOKFlag)
        {
            $showBetTable[] = array("bettype" => $g_betname_3or5[$betSubIdx] . "<input type=\"hidden\" name=\"r{$bettype}_{$valNum}_{$showSubid}\" value=\"{$setMomney}\" />", "nums" => $RateConfig_3d->getBetContent($bettype, $valNum), "rate" => "{$rate}<input type=\"hidden\" name=\"rate{$bettype}v{$valNum}v{$showSubid}\" value=\"{$rate}\" />", "betmoney" => $setMomney, "betflag" => true);
        }
    }
    $ui->header();
    echo "<form action=\"op.php?op=member_3d&fp=betg3_do&palygroup=" . $bettypegroup . "&gametype=" . $gametype . "&disk=" . $disk . "\" method=\"post\" onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
    echo "<input type=\"hidden\" value=\"" . $bettypegroup . "\" name=\"bettypegroup\" />";
    echo "<input type=\"hidden\" value=\"" . $disk . "\" name=\"disk\" />";
    echo "<input type=\"hidden\" value=\"" . $showSubid . "\" name=\"subid\" />";
    echo "<table class=\"tblMy3D\">";
    echo "<thead><tr class=\"title0 bgImg_" . $gametype . "\"><th colspan=5>" . $tblName . " 第" . $round . "期 您下注的是：</th></tr>";
    echo "<tr class=\"bgClc_" . $gametype . "\"><th>下注方式</th><th>下注内容</th><th>盘类</th><th>赔率</th><th>下注金额</th></tr></thead>";
    echo "<tbody>";
    $totalmon = 0;
    foreach ($showBetTable as $val)
    {
        echo "<tr class=\"td2\">";
        echo "<td>" . $val['bettype'] . "</td>";
        echo "<td>" . $val['nums'] . "</td>";
        echo "<td>" . $diskStr2 . "</td>";
        echo "<td>" . $val['rate'] . "</td>";
        echo "<td align=\"right\">" . $val['betmoney'] . "</td>";
        if ($val['betflag'])
        {
            $totalmon += $val['betmoney'];
        }
        echo "</tr>";
    }
    $timebtnType = getvar("timebtnType") == "checkbox" ? "checkbox" : "text";
    $backurl = "op.php?op=member_3d&fp=bet&palygroup={$bettypegroup}&timebtnType={$timebtnType}&gametype={$gametype}&disk={$disk}&subid={$showSubid}";
    if (0 < $totalmon)
    {
        echo "<tr class=\"bgClc_" . $gametype . "\" align=\"right\"><td colspan=\"4\">合计</td><td>" . $totalmon . "</td></tr>";
        $btnStr = "<input type=\"submit\" name=\"submit\" value=\"确定下注\" />&nbsp;&nbsp;<input name=\"reset\" type=\"reset\" value=\"取消下注\" onclick=\"javascript:window.top.mainFrame.location.href='" . $backurl . "';\" />";
        $focusStr = "document.forms[0].submit.focus();";
    }
    else
    {
        echo "<tr class=\"red\"><td colspan=\"5\" align=\"center\">无任何可下注资料</td></tr>";
        $btnStr = "<input name=\"reset\" type=\"reset\" value=\"回上一页\" onclick=\"javascript:window.top.mainFrame.location.href='" . $backurl . "';\" />";
        $focusStr = "";
    }
    echo "</tbody>";
    echo "</table>";
    echo $btnStr;
    echo "<input type=\"hidden\" value=\"" . $timebtnType . "\" name=\"timebtnType\" id=\"timebtnType\" />";
    echo "</form>";
    echo "<script>";
    echo $focusStr;
    echo "</script>";
    $ui->footer();
}